﻿using System;
using System.Numerics;
using System.Text;
using Me.Prettyprint.Cassandra.Utils;
using Me.Prettyprint.Hector.Api.Ddl;

namespace Me.Prettyprint.Cassandra.Serializers
{
    /// <summary>
    /// BigIntegerSerializer handles the conversion between big/little endian
    /// encoding to make sure data is reading across platforms.
    /// </summary>
    public class BigIntegerSerializer : AbstractSerializer<BigInteger>
    {
        public static BigIntegerSerializer Instance = new BigIntegerSerializer();

        public BigIntegerSerializer()
        {
        }
        public override ComparatorType GetComparatorType()
        {
            return ComparatorType.INTEGERTYPE;
        }
        override public ComparatorType ComparatorType
        {
            get
            {
                return ComparatorType.INTEGERTYPE;
            }

        }
        public override byte[] ToBytes(System.Numerics.BigInteger obj)
        {
            return ConvertToBigEndianBytes(obj.ToByteArray());
        }
        public override Utils.ByteBuffer ToByteBuffer(System.Numerics.BigInteger obj)
        {
            return new ByteBuffer(ToBytes(obj));
        }
        public override System.Numerics.BigInteger FromBytes(byte[] bytes)
        {
            return new System.Numerics.BigInteger(ConvertFromBigEndianBytes(bytes));
        }
        public override System.Numerics.BigInteger FromByteBuffer(ByteBuffer buff)
        {
            return FromBytes(buff.GetBuffer());
        }
    }
}
